home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Champak 138
/
Volume 138 Aug 19 2011 - Damaged.iso
/
Games
/
hopes_babysitting_maze.swf
/
scripts
/
__Packages
/
Classes
/
bsmLevel.as
< prev
next >
Wrap
Text File
|
2011-08-19
|
13KB
|
448 lines
class Classes.bsmLevel
{
var BABYTIMER_MAX = 15;
var SPECIALTIMER_MAX = 11;
var hdAssetID = "mc_HD";
var z_hd = 5;
var z_playerMin = 200;
var z_enemyMin = 100;
var z_iconMin = 10;
var n_timerMax = 60;
var SSP = {x:530,y:53};
function bsmLevel(t_engine)
{
this.engine = t_engine;
}
function get timer()
{
Math.ceil(this.n_timer);
}
function step(t_elapsed)
{
this.babyTimer -= t_elapsed;
if(this.babyTimer < 0)
{
var _loc3_ = this.engine.gameRoot.house_mc.crib_mc.baby_mc;
if(this.babySadness == 0)
{
_loc3_.gotoAndStop("happy");
}
else if(this.babySadness <= 2)
{
_loc3_.gotoAndStop("cry");
}
_loc3_.anim.gotoAndPlay(1);
this.babySadness = this.babySadness + 1;
this.babyTimer = this.BABYTIMER_MAX;
}
this.n_timer -= t_elapsed;
if(this.n_timer <= 0)
{
this.n_timer = 0;
this.engine.gameOver();
return undefined;
}
if(this.n_timer < 20)
{
if(this.alertLowTime)
{
this.engine.gameRoot.mc_watch.gotoAndPlay("twentysec");
this.alertLowTime = false;
}
else if(this.n_timer < 10 && this.alertWarningTime)
{
this.engine.gameRoot.mc_watch.gotoAndPlay("tensec");
this.alertWarningTime = false;
}
}
this.engine.gameRoot.mc_clock.mc_anim.gotoAndStop(this.clockFrames - Math.floor(this.clockFrames * (this.n_timer / this.n_timerMax)));
this.player.update(t_elapsed);
this.stepEnemy(t_elapsed);
if(!this.player.hidden)
{
this.player.update(t_elapsed);
this.runEntityHD();
this.player.move();
this.runSwingHD();
if(this.babyReady)
{
this.runBabyHD();
}
else
{
this.runIconHD(t_elapsed);
}
}
this.player.render();
}
function runSwingHD()
{
if(Math.sqrt((this.player.x - this.SSP.x) * (this.player.x - this.SSP.x) + (this.player.y - this.SSP.y) * (this.player.y - this.SSP.y)) < 30)
{
this.engine.gameRoot.house_mc.swingset_mc.play();
}
}
function start(t_path)
{
this.reset();
this.clear();
this.path = t_path;
this.attachHD();
this.iconsFound = 0;
this.iconsTotal = this.iconData.length;
this.babyReady = false;
this.spawnPlayer();
this.spawnIcons();
this.setSpecial();
this.clockFrames = this.engine.gameRoot.mc_clock.mc_anim._totalFrames;
this.a_enemy = [];
this.spawnEnemy();
}
function setSpecial()
{
var _loc2_ = this.a_icons.length;
var _loc3_ = 0;
while(true)
{
_loc2_;
if(!_loc2_--)
{
break;
}
if(this.a_icons[_loc2_].specialNum == this.currentSpecial && this.a_icons[_loc2_].isActive)
{
this.a_icons[_loc2_].goSpecial(this.specialTimer);
_loc3_ = _loc3_ + 1;
}
}
if(_loc3_ > 1)
{
this.specialTimer += 6;
}
}
function reset()
{
this.n_timer = this.n_timerMax;
this.specialTimer = this.SPECIALTIMER_MAX;
this.currentSpecial = 0;
this.babyTimer = this.BABYTIMER_MAX;
this.babySadness = 0;
this.engine.gameRoot.house_mc.crib_mc.baby_mc.gotoAndStop("happy");
this.z_playerCurrent = this.z_playerMin;
this.z_iconCurrent = this.z_iconMin;
this.z_enemyCurrent = this.z_enemyMin;
}
function clear()
{
this.player.clear();
this.player = null;
this.alertLowTime = true;
this.alertWarningTime = true;
this.engine.gameRoot.babyArrow_mc.gotoAndStop("off");
this.clearIcons();
this.clearEnemy();
}
function attachHD()
{
this.hd = this.path.attachMovie(this.hdAssetID,"hd",this.z_hd);
this.generateAIPoints();
}
function generateAIPoints()
{
this.a_aiPoints = [];
this.a_aiPoints.push({point:"point1",adj:["point2","point8"]});
this.a_aiPoints.push({point:"point2",adj:["point1","point3","point7"]});
this.a_aiPoints.push({point:"point3",adj:["point2","point4"]});
this.a_aiPoints.push({point:"point4",adj:["point3","point5"]});
this.a_aiPoints.push({point:"point5",adj:["point4","point6"]});
this.a_aiPoints.push({point:"point6",adj:["point5","point7","point18"]});
this.a_aiPoints.push({point:"point7",adj:["point6","point2","point8"]});
this.a_aiPoints.push({point:"point8",adj:["point7","point1","point9"]});
this.a_aiPoints.push({point:"point9",adj:["point8","point10","point13"]});
this.a_aiPoints.push({point:"point10",adj:["point9","point11"]});
this.a_aiPoints.push({point:"point11",adj:["point10","point12"]});
this.a_aiPoints.push({point:"point12",adj:["point11","point13"]});
this.a_aiPoints.push({point:"point13",adj:["point12","point14","point9"]});
this.a_aiPoints.push({point:"point14",adj:["point13","point15","point19"]});
this.a_aiPoints.push({point:"point15",adj:["point14","point20"]});
this.a_aiPoints.push({point:"point16",adj:["point20","point17"]});
this.a_aiPoints.push({point:"point17",adj:["point16","point18"]});
this.a_aiPoints.push({point:"point18",adj:["point17","point19"]});
this.a_aiPoints.push({point:"point19",adj:["point18","point14"]});
this.a_aiPoints.push({point:"point20",adj:["point15","point16","point21"]});
this.a_aiPoints.push({point:"point21",adj:["point20","point22"]});
this.a_aiPoints.push({point:"point22",adj:["point21","point23","point24"]});
this.a_aiPoints.push({point:"point23",adj:["point22"]});
this.a_aiPoints.push({point:"point24",adj:["point22","point25"]});
this.a_aiPoints.push({point:"point25",adj:["point24","point8"]});
}
function runEntityHD()
{
var _loc2_ = this.a_enemy.length;
while(true)
{
_loc2_;
if(!_loc2_--)
{
break;
}
if(this.player.mc.hitTest(this.a_enemy[_loc2_].mc))
{
this.player.hit(this.a_enemy[_loc2_]);
this.a_enemy[_loc2_].hitReact();
}
}
}
function runIconHD(el)
{
var _loc2_ = this.a_icons.length;
while(true)
{
_loc2_;
if(!_loc2_--)
{
break;
}
if(this.a_icons[_loc2_].isSpecial)
{
this.a_icons[_loc2_].decSpecial(el);
}
if(this.a_icons[_loc2_].isActive && Math.abs(this.player.x - this.a_icons[_loc2_].x) < 20)
{
if(this.a_icons[_loc2_].mc.hitTest(this.player.mc))
{
if(this.a_icons[_loc2_].isSpecial)
{
this.currentSpecial = this.currentSpecial + 1;
this.setSpecial();
}
this.a_icons[_loc2_].pickup();
this.engine.addScore(this.a_icons[_loc2_].value);
this.iconsFound = this.iconsFound + 1;
if(this.iconsFound == this.iconsTotal)
{
this.startBaby();
}
}
}
}
}
function runBabyHD()
{
if(this.engine.gameRoot.babyArrow_mc.hitTest(this.player.mc))
{
this.engine.gameRoot.babyArrow_mc.gotoAndStop("off");
this.engine.startScript("meetBaby");
}
}
function startBaby()
{
this.engine.gameRoot.babyArrow_mc.gotoAndStop("on");
this.engine.playSound("pickupFinal");
this.babyReady = true;
}
function findPoint(t_point)
{
var _loc2_ = this.a_aiPoints.length;
while(true)
{
_loc2_;
if(!_loc2_--)
{
break;
}
if(t_point == this.a_aiPoints[_loc2_].point)
{
return _loc2_;
}
}
return 0;
}
function findAdjacentPoint(t_point)
{
var _loc3_ = undefined;
var _loc2_ = undefined;
var _loc6_ = undefined;
_loc3_ = this.a_aiPoints[t_point].adj;
var _loc5_ = _loc3_.length;
_loc2_ = Math.ceil(Math.random() * _loc3_.length) - 1;
if(_loc2_ < 0)
{
_loc2_ = 0;
}
_loc2_ = _loc3_[_loc2_];
if(_loc2_ == undefined)
{
trace("OMG ERROR");
return t_point;
}
return this.findPoint(_loc2_);
}
function findFurthestPointFromPlayer(t_point)
{
var a_adj;
var t_pointMC;
var n_dist;
var n_winner;
var n_result;
var xDiff;
var yDiff;
var d;
a_adj = this.a_aiPoints[t_point].adj;
n_dist = 0;
d = a_adj.length;
while(d--)
{
t_pointMC = eval(this.hd + "." + a_adj[d]);
xDiff = this.player.x - t_pointMC._x;
yDiff = this.player.y - t_pointMC._y;
n_result = Math.sqrt(xDiff * xDiff + yDiff * yDiff);
if(n_result > n_dist)
{
n_dist = n_result;
n_winner = a_adj[d];
}
}
if(n_winner == undefined)
{
trace("OMG ERROR");
return t_point;
}
return this.findPoint(n_winner);
}
function findClosestPointToPlayer(t_point)
{
var a_adj;
var t_pointMC;
var n_dist;
var n_winner;
var n_result;
var xDiff;
var yDiff;
var d;
a_adj = this.a_aiPoints[t_point].adj;
n_dist = 2000;
d = a_adj.length;
while(d--)
{
t_pointMC = eval(this.hd + "." + a_adj[d]);
xDiff = this.player.x - t_pointMC._x;
yDiff = this.player.y - t_pointMC._y;
n_result = Math.sqrt(xDiff * xDiff + yDiff * yDiff);
if(n_result < n_dist)
{
n_dist = n_result;
n_winner = a_adj[d];
}
}
if(n_winner == undefined)
{
trace("OMG ERROR");
return t_point;
}
return this.findPoint(n_winner);
}
function spawnPlayer()
{
this.player = new Classes.bsmPlayer(this.playerData,this);
this.player.spawn(this.path,this.z_playerCurrent);
this.player.mc.gotoAndStop("glow");
this.z_playerCurrent = this.z_playerCurrent + 1;
}
function stepEnemy(t_elapsed)
{
var _loc2_ = this.a_enemy.length;
while(true)
{
_loc2_;
if(!_loc2_--)
{
break;
}
this.a_enemy[_loc2_].step(t_elapsed);
}
}
function spawnEnemy()
{
this.a_enemy = [];
var _loc3_ = this.enemyData.length;
while(true)
{
_loc3_;
if(!_loc3_--)
{
break;
}
var _loc2_ = new Classes.bsmEnemy(this.enemyData[_loc3_],this);
this.a_enemy.push(_loc2_);
_loc2_.spawn(this.path,this.z_enemyCurrent);
this.z_enemyCurrent = this.z_enemyCurrent + 1;
}
}
function spawnSpecific(t_type)
{
var _loc3_ = this.enemyData.length;
while(true)
{
_loc3_;
if(!_loc3_--)
{
break;
}
if(this.enemyData[_loc3_].type == t_type)
{
var _loc2_ = new Classes.bsmEnemy(this.enemyData[_loc3_],this);
this.a_enemy.push(_loc2_);
_loc2_.spawn(this.path,this.z_enemyCurrent);
this.z_enemyCurrent = this.z_enemyCurrent + 1;
}
}
}
function clearEnemy()
{
var _loc2_ = this.a_enemy.length;
while(true)
{
_loc2_;
if(!_loc2_--)
{
break;
}
this.a_enemy[_loc2_].clear();
}
this.a_enemy = [];
}
function spawnIcons()
{
this.a_icons = [];
var _loc3_ = this.iconData.length;
var _loc2_ = undefined;
while(true)
{
_loc3_;
if(!_loc3_--)
{
break;
}
_loc2_ = new Classes.bsmIcon(this.iconData[_loc3_],this,this.iconFrameNum);
this.a_icons.push(_loc2_);
_loc2_.spawn(this.path,this.z_iconCurrent);
this.z_iconCurrent = this.z_iconCurrent + 1;
}
}
function clearIcons()
{
var _loc2_ = this.a_icons.length;
while(true)
{
_loc2_;
if(!_loc2_--)
{
break;
}
this.a_icons[_loc2_].clear();
}
this.a_icons = [];
}
}